from django.db import models
from webpos.storage import ImageStorage


class Products(models.Model):
    pid = models.AutoField(primary_key=True)
    Item_Code = models.CharField(max_length=50, unique=True)
    Item_Dri = models.CharField(max_length=100, null=True)
    Brand = models.CharField(max_length=20)
    Item_Season = models.CharField(max_length=10)
    Item_Gender = models.CharField(max_length=10)
    Division = models.CharField(max_length=30)
    Category = models.ForeignKey('Category', related_name='Products_Category', on_delete=models.CASCADE)
    SubCategory = models.CharField(max_length=30)
    ReatilPrice = models.DecimalField(max_digits=10, decimal_places=2)
    Sug_Cost = models.DecimalField(max_digits=10, decimal_places=4)
    isActive = models.BooleanField(default=True)
    TAG_CHOICES = (
        (u'0', u'常规'),
        (u'1', u'新品'),
        (u'2', u'精选'),
        (u'3', u'爆款'),
        (u'4', u'特惠'),
    )
    Tag1 = models.CharField(max_length=10, choices=TAG_CHOICES, default='1')
    Tag2 = models.CharField(max_length=10, choices=TAG_CHOICES, null=True)
    Tag3 = models.CharField(max_length=10, choices=TAG_CHOICES, null=True)
    # 产品图片是一个FileField——注意这里必须是“相对路径”，不能是/pic/这样的绝对路径
    pt_img = models.ImageField(upload_to='pic/%Y', default='pic/default.jpg', storage=ImageStorage())
    Create_Date = models.DateTimeField(auto_now_add=True)
    Modify_date = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = 'Product'
        ordering = ['-pid', ]

    def __str__(self):
        return self.Item_Code


class Category(models.Model):
    name = models.CharField(max_length=30)

    class Meta:
        verbose_name = 'Category'

    def __str__(self):
        return self.name

